package GUI;

import javax.swing.JFrame;
import javax.swing.JLabel;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;

import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.ImageIcon;
import javax.swing.JButton;

import sql.Check_login;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.sql.SQLException;
import java.util.ArrayList;

import logic.LogicLogin;
import java.awt.Color;

public class Login extends JFrame{
	private JTextField textField;
	private JTextField textField_1;
	ArrayList<String> user= new ArrayList<String>();
	private String flag="-1";
	public Login() {
		getContentPane().setLayout(null);
		
		JLabel lblUsername = new JLabel("Username");
		lblUsername.setFont(new Font("Tahoma", Font.PLAIN, 14));
		lblUsername.setBounds(87, 102, 71, 14);
		getContentPane().add(lblUsername);
		
		JLabel lblPassword = new JLabel("Password");
		lblPassword.setFont(new Font("Tahoma", Font.PLAIN, 14));
		lblPassword.setBounds(87, 140, 71, 14);
		getContentPane().add(lblPassword);
		
		textField = new JTextField();
		textField.setBounds(182, 101, 148, 20);
		getContentPane().add(textField);
		textField.setColumns(10);
		
		textField_1 = new JTextField();
		textField_1.setBounds(182, 139, 148, 20);
		getContentPane().add(textField_1);
		textField_1.setColumns(10);
		
		JButton btnLogin = new JButton("Login");
		btnLogin.addActionListener(new ActionListener() {
			
			public void actionPerformed(ActionEvent arg0) {
				
				
				try {
					
					LogicLogin ll = new LogicLogin(textField.getText(), textField_1.getText());
					user=ll.checkLogin();
					
						if(!user.get(0).equals("-1"))
						{
							 mainscreen mains = new mainscreen(user.get(0),user.get(1),user.get(2));
							 mains.setSize(1000, 700);
							 mains.setVisible(true);
							 setVisible(false);
							
						}
						else
						{
							
							JOptionPane.showMessageDialog(null, "Error : Password or Username are wrong");
						}
					} 
				catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
			}
		});
		btnLogin.setFont(new Font("Tahoma", Font.PLAIN, 16));
		btnLogin.setBounds(182, 179, 148, 23);
		getContentPane().add(btnLogin);
		
		JLabel lblMtl = new JLabel("MTL");
		lblMtl.setForeground(Color.BLUE);
		lblMtl.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 45));
		lblMtl.setBounds(195, 28, 148, 49);
		getContentPane().add(lblMtl);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
	}
}
